
import pyAxios from "./http";

//这几个接口应该移动到教师处getCourseList  getCourseData 和课程相关的
async function getCourseList() {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/getCourseList',
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

async function getCourseData(courseId) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/getCourseData',
            params:{
                courseId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

async function addChapter(courseId) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/addChapter',
            params:{
                courseId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

// 获取该学生的班级信息
async function changeOrder(fromData) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/admin/changeOrder',
            data:fromData
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

async function deleteChapter(courseId,chapterId) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/deleteChapter',
            params:{
                courseId,
                chapterId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}
//修改标题
async function updateTitle(courseId,courseTitle) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/updateTitle',
            params:{
                courseId,
                courseTitle
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}
//修改简介
async function updateIntro(courseId,courseIntro) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/updateIntro',
            params:{
                courseId,
                courseIntro
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//获取该章节的数据
async function getEditorDataById(chapterId) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/getEditorDataById',
            params:{
                chapterId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//获取该章节的数据
async function saveMdEditor(form) {
    try {
        const response = await pyAxios({
            method: 'post',
            url:'/admin/saveMdEditor',
            data:form
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

// 管理员发送公告
async function sendAnnouncement(InformData) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/admin/sendAnnouncement',
            data: InformData
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//获取教师数据
async function getAllTeacher() {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/getAllTeacher',
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//获取教师申请数据
async function getAllRoleApply() {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/getAllRoleApply',
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//通过申请
async function passRoleApply(applyId) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/passRoleApply',
            params:{
                applyId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//拒绝申请
async function refuseRoleApply(applyId) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/refuseRoleApply',
            params:{
                applyId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//开除
async function expelTeacher(userId) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/expelTeacher',
            params:{
                userId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//授权教师权限
async function becomeTeacher(userId) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/admin/becomeTeacher',
            params:{
                userId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}


//获取所有学生的账号信息
async function getAllStudent() {
    try {
        const response = await pyAxios({
            method:'get',
            url:'/admin/getAllStudent',
        })
        return response;
    } catch (error) {
        console.log(error);
        
    }
}



export default {becomeTeacher,getAllStudent,expelTeacher,passRoleApply,refuseRoleApply,getAllRoleApply,getAllTeacher,sendAnnouncement,saveMdEditor,getEditorDataById,updateTitle,updateIntro,deleteChapter,changeOrder,addChapter,getCourseList,getCourseData}